package fr.oz.mobile.module.profile 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import fr.oz.core.datas.ProfilList;
	import fr.oz.core.events.ProfilEvent;
	import fr.oz.mobile.common.ui.NavSeparator;
	/**
	 * ...
	 * @author Fazermokeur
	 */
	public class ProfilNav extends Sprite
	{
		private var a_item:Vector.<ProfilNavItem>;
		
		public function ProfilNav() 
		{
			addEventListener(Event.ADDED_TO_STAGE, init);
			a_item = new Vector.<ProfilNavItem>();
		}
		
		private function init(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			addEventListener(Event.REMOVED_FROM_STAGE, dispose);
			
			trace("4: PROFILNAV ADDED TO STAGE");
			
			var len:int = ProfilList.profils.length;
			
			trace("3: len = " + len);
			var pad:ProfilNavItem;
			for (var i:int = 0; i < len; i++) 
			{
				pad = new ProfilNavItem(ProfilList.profils[i]);
				addChild(pad);
				pad.y = i * 90;
				pad.addEventListener(MouseEvent.CLICK, handleClick);
				
				var separator:NavSeparator = new NavSeparator();
				addChild(separator);
				separator.y = (i + 1) * 90;
				
				a_item.push(pad);
			}
		}
		
		private function handleClick(e:MouseEvent):void 
		{
			trace((e.currentTarget as ProfilNavItem).profil.name);
			dispatchEvent(new ProfilEvent(ProfilEvent.PROFIL_SELECTED, (e.currentTarget as ProfilNavItem).profil));
		}
		
		private function dispose(e:Event):void 
		{
			removeEventListener(Event.REMOVED_FROM_STAGE, dispose);
			
		}
		
	}

}